package io.renren.modules.dangan.controller;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.util.IdUtil;
import io.renren.common.annotation.FlhFilter;
import io.renren.common.annotation.SysLog;
import io.renren.common.annotation.SzdFilter;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.dangan.entity.DaDjgllEntity;
import io.renren.modules.dangan.service.DaDjgllService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 地籍类档案
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-08-03 22:04:03
 */
@RestController
@RequestMapping("/dadjgll")
@CrossOrigin
public class DaDjgllController {
    @Autowired
    private DaDjgllService daDjgllService;



    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("dangan:dadjgll:list")
    @FlhFilter
    @SzdFilter
    @SysLog("查询业务类档案")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = daDjgllService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{nbxh}")
    @RequiresPermissions("dangan:dadjgll:info")
    public R info(@PathVariable("nbxh") String nbxh){
        DaDjgllEntity daDjgll = daDjgllService.getById(nbxh);

        return R.ok().put("daDjgll", daDjgll);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("dangan:dadjgll:save")
    public R save(DaDjgllEntity daDjgll){
        daDjgll.setNbxh(IdUtil.createSnowflake(1,1).nextIdStr());
        daDjgll.setNd(daDjgll.getNd().substring(0,4));
        daDjgllService.save(daDjgll);

        return R.ok().put("data",daDjgll);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dangan:dadjgll:update")
    public R update(DaDjgllEntity daDjgll){
        ValidatorUtils.validateEntity(daDjgll);
        daDjgllService.updateById(daDjgll);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dangan:dadjgll:delete")
    public R delete(String[] nbxhs){
        daDjgllService.removeByIds(Arrays.asList(nbxhs));

        return R.ok();
    }

}
